return success;
}
-bool FileSystem::uncheckedRenameReplace(const QString &originFileName,
- const QString &destinationFileName,
- QString *errorString)
-{
-#ifndef Q_OS_WIN
- bool success = false;
- QFile orig(originFileName);
- // We want a rename that also overwrites. QFile::rename does not overwrite.
- // Qt 5.1 has QSaveFile::renameOverwrite we could use.
- // ### FIXME
- success = true;
- bool destExists = fileExists(destinationFileName);
- if (destExists && !QFile::remove(destinationFileName)) {
- *errorString = orig.errorString();
- qCWarning(lcFileSystem) << "Target file could not be removed.";
- success = false;
- }
- if (success) {
- success = orig.rename(destinationFileName);
- }
- if (!success) {
- *errorString = orig.errorString();
- qCWarning(lcFileSystem) << "Renaming temp file to final failed: " << *errorString;
- return false;
- }
-
-#else //Q_OS_WIN
- // You can not overwrite a read-only file on windows.
- if (!isWritable(destinationFileName)) {
- setFileReadOnly(destinationFileName, false);
- }
-
- BOOL ok = 0;
- QString orig = longWinPath(originFileName);
- QString dest = longWinPath(destinationFileName);
-
- ok = MoveFileEx((wchar_t *)orig.utf16(),
- (wchar_t *)dest.utf16(),
- MOVEFILE_REPLACE_EXISTING + MOVEFILE_COPY_ALLOWED + MOVEFILE_WRITE_THROUGH);
- if (!ok) {
- *errorString = Utility::formatWinError(GetLastError());
- qCWarning(lcFileSystem) << "Renaming temp file to final failed: " << *errorString;
- return false;
- }
-#endif
- return true;
-}
-
bool FileSystem::openAndSeekFileSharedRead(QFile *file, QString *errorOrNull, qint64 seek)
{
QString errorDummy;
}
}
+bool FileSystem::uncheckedRenameReplace(const QString &originFileName, const QString &destinationFileName, QString *errorString)
+{
+#ifndef Q_OS_WIN
+ bool success = false;
+ QFile orig(originFileName);
+ // We want a rename that also overwrites. QFile::rename does not overwrite.
+ // Qt 5.1 has QSaveFile::renameOverwrite we could use.
+ // ### FIXME
+ success = true;
+ bool destExists = fileExists(destinationFileName);
+ if (destExists && !QFile::remove(destinationFileName)) {
+ *errorString = orig.errorString();
+ qCWarning(lcFileSystem) << "Target file could not be removed.";
+ success = false;
+ }
+ if (success) {
+ success = orig.rename(destinationFileName);
+ }
+ if (!success) {
+ *errorString = orig.errorString();
+ qCWarning(lcFileSystem) << "Renaming temp file to final failed: " << *errorString;
+ return false;
+ }
+#else //Q_OS_WIN
+ const auto originFileInfo = QFileInfo{originFileName};
+ const auto originParentFolderPath = originFileInfo.dir().absolutePath();
+ FilePermissionsRestore renameEnabler{originParentFolderPath, FileSystem::FolderPermissions::ReadWrite};
+ // You can not overwrite a read-only file on windows.
+ if (!isWritable(destinationFileName)) {
+ setFileReadOnly(destinationFileName, false);
+ }
+
+ BOOL ok = 0;
+ QString orig = longWinPath(originFileName);
+ QString dest = longWinPath(destinationFileName);
+
+ ok = MoveFileEx((wchar_t *)orig.utf16(),
+ (wchar_t *)dest.utf16(),
+ MOVEFILE_REPLACE_EXISTING + MOVEFILE_COPY_ALLOWED + MOVEFILE_WRITE_THROUGH);
+ if (!ok) {
+ *errorString = Utility::formatWinError(GetLastError());
+ qCWarning(lcFileSystem) << "Renaming temp file to final failed: " << *errorString;
+ return false;
+ }
+#endif
+ return true;
+}
+
} // namespace OCC
#endif
}
+static bool isReadOnlyFolder(const std::wstring &path)
+{
+ return FileSystem::isFolderReadOnly(std::filesystem::path{path});
+}
+
SyncFileItemPtr findDiscoveryItem(const SyncFileItemVector &spy, const QString &path)
{
for (const auto &item : spy) {
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- auto folderStatus = std::filesystem::status(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder")).toStdWString());
- QVERIFY(folderStatus.permissions() & std::filesystem::perms::owner_read);
- QVERIFY(!static_cast<bool>(folderStatus.permissions() & std::filesystem::perms::owner_write));
+ QVERIFY(isReadOnlyFolder(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder")).toStdWString()));
remote.find("testFolder")->permissions = RemotePermissions::fromServerString("CKWDNVRSM");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- folderStatus = std::filesystem::status(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder")).toStdWString());
- QVERIFY(folderStatus.permissions() & std::filesystem::perms::owner_read);
- QVERIFY(folderStatus.permissions() & std::filesystem::perms::owner_write);
+ QVERIFY(!isReadOnlyFolder(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder")).toStdWString()));
remote.find("testFolder")->permissions = RemotePermissions::fromServerString("M");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- folderStatus = std::filesystem::status(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder")).toStdWString());
- QVERIFY(folderStatus.permissions() & std::filesystem::perms::owner_read);
- QVERIFY(!static_cast<bool>(folderStatus.permissions() & std::filesystem::perms::owner_write));
+ QVERIFY(isReadOnlyFolder(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder")).toStdWString()));
}
void testChangePermissionsForFolderHierarchy()
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- auto testFolderStatus = std::filesystem::status(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder")).toStdWString());
- QVERIFY(testFolderStatus.permissions() & std::filesystem::perms::owner_read);
- QVERIFY(!static_cast<bool>(testFolderStatus.permissions() & std::filesystem::perms::owner_write));
- auto subFolderReadWriteStatus = std::filesystem::status(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder/subFolderReadWrite")).toStdWString());
- QVERIFY(subFolderReadWriteStatus.permissions() & std::filesystem::perms::owner_read);
- QVERIFY(subFolderReadWriteStatus.permissions() & std::filesystem::perms::owner_write);
- auto subFolderReadOnlyStatus = std::filesystem::status(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder/subFolderReadOnly")).toStdWString());
- QVERIFY(subFolderReadOnlyStatus.permissions() & std::filesystem::perms::owner_read);
- QVERIFY(!static_cast<bool>(subFolderReadOnlyStatus.permissions() & std::filesystem::perms::owner_write));
+ QVERIFY(isReadOnlyFolder(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder")).toStdWString()));
+ QVERIFY(!isReadOnlyFolder(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder/subFolderReadWrite")).toStdWString()));
+ QVERIFY(isReadOnlyFolder(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder/subFolderReadOnly")).toStdWString()));
remote.find("testFolder/subFolderReadOnly")->permissions = RemotePermissions::fromServerString("CKWDNVRSm");
remote.find("testFolder/subFolderReadWrite")->permissions = RemotePermissions::fromServerString("m");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- subFolderReadWriteStatus = std::filesystem::status(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder/subFolderReadWrite")).toStdWString());
- QVERIFY(subFolderReadWriteStatus.permissions() & std::filesystem::perms::owner_read);
- QVERIFY(!static_cast<bool>(subFolderReadWriteStatus.permissions() & std::filesystem::perms::owner_write));
- subFolderReadOnlyStatus = std::filesystem::status(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder/subFolderReadOnly")).toStdWString());
- QVERIFY(subFolderReadOnlyStatus.permissions() & std::filesystem::perms::owner_read);
- QVERIFY(subFolderReadOnlyStatus.permissions() & std::filesystem::perms::owner_write);
+ QVERIFY(isReadOnlyFolder(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder")).toStdWString()));
+ QVERIFY(isReadOnlyFolder(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder/subFolderReadWrite")).toStdWString()));
+ QVERIFY(!isReadOnlyFolder(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder/subFolderReadOnly")).toStdWString()));
remote.rename("testFolder/subFolderReadOnly", "testFolder/subFolderReadWriteNew");
remote.rename("testFolder/subFolderReadWrite", "testFolder/subFolderReadOnlyNew");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
- testFolderStatus = std::filesystem::status(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder")).toStdWString());
- QVERIFY(testFolderStatus.permissions() & std::filesystem::perms::owner_read);
- QVERIFY(!static_cast<bool>(testFolderStatus.permissions() & std::filesystem::perms::owner_write));
+ QVERIFY(isReadOnlyFolder(static_cast<QString>(fakeFolder.localPath() + QStringLiteral("/testFolder")).toStdWString()));
}
void testDeleteChildItemsInReadOnlyFolder()